"""
接口路由 Request VO
"""

import utils.enum_utils as enum
from models import (
    ListRequestBase,
    QueryFieldBase,
    RequestBase,
)
from my_typing import *
from utils.data_utils.special import ObjectIdStr
from utils.validator_utils.pydantic_validator.field import (
    PathCharField,
    QueryCharField,
    QueryNormalField,
)


class APIRoutePathField:
    """ 接口路由 | 路径 | 字段 """

    route_id: ObjectIdStr = PathCharField(..., title="接口路由 ID")


class APIRouteDetailRequest(RequestBase):
    """ 接口路由 | 详情 | 请求 """

    route_id: ObjectIdStr = APIRoutePathField.route_id


class APIRouteListRequest(ListRequestBase):
    """ 接口路由 | 列表 | 请求 """

    # -------------------- 排序字段 --------------------
    sort_by_dependency: enum.MongoSortOrNone = QueryCharField(None, title="根据依赖项排序")
    sort_by_method: enum.MongoSortOrNone = QueryCharField(None, title="根据请求方法排序")
    sort_by_path: enum.MongoSortOrNone = QueryCharField(None, title="根据请求路径排序")
    sort_by_summary: enum.MongoSortOrNone = QueryCharField(None, title="根据路由描述排序")
    sort_by_tag: enum.MongoSortOrNone = QueryCharField(None, title="根据标签排序")
    sort_by_update_time: enum.MongoSortOrNone = QueryCharField(None, title="根据更新时间排序")

    # -------------------- 查询字段 --------------------
    dependency: StrOrNone = QueryCharField(None, title="依赖项")
    deprecated: BoolOrNone = QueryNormalField(None, title="是否已废弃")
    method: enum.Method | None = QueryCharField(None, title="请求方法")
    name: StrOrNone = QueryCharField(None, title="接口名称")
    path: StrOrNone = QueryCharField(None, title="请求路径")
    summary: StrOrNone = QueryCharField(None, title="路由描述")
    tag: enum.SwaggerTag | None = QueryCharField(None, title="标签")

    # @classmethod
    # def get_openapi_extra(cls):
    #     return {
    #         "parameters": [
    #             {
    #                 "name": field.name,
    #                 "in": "query",
    #                 "required": field.required,
    #                 "schema": {"type": "string"}
    #             }
    #             for field in cls.__fields__.values()
    #         ]
    #     }

    @classmethod
    def from_query(
        cls,
        page: int = QueryFieldBase.page,
        page_size: int = QueryFieldBase.page_size,
        sort_by_dependency: enum.MongoSortOrNone = QueryCharField(None, title="根据依赖项排序"),
        sort_by_method: enum.MongoSortOrNone = QueryCharField(None, title="根据请求方法排序"),
        sort_by_path: enum.MongoSortOrNone = QueryCharField(None, title="根据请求路径排序"),
        sort_by_summary: enum.MongoSortOrNone = QueryCharField(None, title="根据路由描述排序"),
        sort_by_tag: enum.MongoSortOrNone = QueryCharField(None, title="根据标签排序"),
        sort_by_update_time: enum.MongoSortOrNone = QueryCharField(None, title="根据更新时间排序"),
        dependency: StrOrNone = QueryCharField(None, title="依赖项"),
        deprecated: BoolOrNone = QueryNormalField(None, title="是否已废弃"),
        method: enum.Method | None = QueryCharField(None, title="请求方法"),
        name: StrOrNone = QueryCharField(None, title="接口名称"),
        path: StrOrNone = QueryCharField(None, title="请求路径"),
        summary: StrOrNone = QueryCharField(None, title="路由描述"),
        tag: enum.SwaggerTag | None = QueryCharField(None, title="标签"),
    ) -> "APIRouteListRequest":
        return cls(
            page=page,
            page_size=page_size,
            sort_by_dependency=sort_by_dependency,
            sort_by_method=sort_by_method,
            sort_by_path=sort_by_path,
            sort_by_summary=sort_by_summary,
            sort_by_tag=sort_by_tag,
            sort_by_update_time=sort_by_update_time,
            dependency=dependency,
            deprecated=deprecated,
            method=method,
            name=name,
            path=path,
            summary=summary,
            tag=tag,
        )
